﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BesAsm.Stormwater.HspfCore;

namespace BesAsm.Stormwater.HspfResults
{
  public class L61ImplandBlock : L61Block
  {
    public L61ImplandBlock(ILandSegment segment)
      : base(segment)
    {
    }

    public override int BlockLineCount { get { return 18; } }

    protected override L61Fluxes ParseFluxes(List<string> blockLines)
    {
      L61Fluxes fluxes = new L61Fluxes(this.Segment.Type);
      int fluxHeaderLine = 0;
      for (int i = 0; i < blockLines.Count; i++)
        if (blockLines[i].Contains("FLUXES"))
        {
          fluxHeaderLine = i;
          break;
        }

      if (fluxHeaderLine == 0)
        throw new Exception("Error parsing flux block");

      string[] tokens = blockLines[fluxHeaderLine + 3].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

      fluxes.Supy = double.Parse(tokens[0]);
      fluxes.Suro = double.Parse(tokens[1]);
      
      return fluxes;

    }

    protected override L61StateVariables ParseStates(List<string> blockLines)
    {
      L61StateVariables states = new L61StateVariables(this.Segment.Type);
      int stateHeaderLine = 0;
      for (int i = 0; i < blockLines.Count; i++)
        if (blockLines[i].Contains("STATE VARIABLES"))
        {
          stateHeaderLine = i;
          break;
        }

      if (stateHeaderLine == 0)
        throw new Exception("Error parsing flux block");

      string[] tokens = blockLines[stateHeaderLine + 3].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

      states.Rets = double.Parse(tokens[0]);
      states.Surs = double.Parse(tokens[1]);

      return states;
    }

    public override Dictionary<string, object> GetResultsDictionary()
    {
      Dictionary<string, object> results = new Dictionary<string, object>();

      results.Add("Date", ResultsDate.ToString("MMMM yyyy"));
      results.Add("SUPY", Fluxes.Supy);
      results.Add("SURO", Fluxes.Suro);      

      return results;
    }
    
  }
}
